package com.share.finance.fund.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.common.Page;
import com.share.finance.fund.mapper.RepaymentRecordMapper;
import com.share.finance.fund.model.db.RepaymentRecord;
import com.share.finance.fund.model.vo.RepaymentRecordPageReq;
import com.share.finance.fund.service.IRepaymentRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 还款计划表  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-21
 */
@Service
public class RepaymentRecordServiceImpl extends ServiceImpl<RepaymentRecordMapper, RepaymentRecord> implements IRepaymentRecordService {
    @Resource
    private RepaymentRecordMapper repaymentRecordMapper;

    @Override
    public Page<RepaymentRecord> pageList(RepaymentRecordPageReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        LambdaQueryWrapper<RepaymentRecord> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(req.getName())) {
            queryWrapper.like(RepaymentRecord::getName, req.getName());
        }
        if (StringUtils.isNotBlank(req.getName())) {
            queryWrapper.like(RepaymentRecord::getName, req.getName());
        }
        if (StringUtils.isNotBlank(req.getSessionId())) {
            queryWrapper.like(RepaymentRecord::getSessionId, req.getSessionId());
        }
        if (StringUtils.isNotBlank(req.getUserId())) {
            queryWrapper.like(RepaymentRecord::getUserId, req.getUserId());
        }

        queryWrapper.orderByDesc(RepaymentRecord::getId);
        List<RepaymentRecord> list = repaymentRecordMapper.selectList(queryWrapper);
        return new Page<>(list, new PageInfo<>(list).getTotal(), req);
    }
}
